/**
 * 管理初始化
 */
var Gdtj = {
    id: "GdtjTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Gdtj.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '股东名称', field: 'gSharehdname', visible: true, align: 'center', valign: 'middle'},
            {title: '股份类型', field: 'gSharestype', visible: true, align: 'center', valign: 'middle'},
            {title: '持有排名', field: 'gRank', visible: true, align: 'center', valign: 'middle'},
            {title: '股票代码', field: 'gDm', visible: true, align: 'center', valign: 'middle'},
            {title: '股票名称', field: 'gSname', visible: true, align: 'center', valign: 'middle'},
            {title: '股东统计截止日', field: 'gRdate', visible: true, align: 'center', valign: 'middle'},
            {title: '持股数', field: 'gSharehdnum', visible: true, align: 'center', valign: 'middle'},
            {title: '持股比例', field: 'gZb', visible: true, align: 'center', valign: 'middle'},
            {title: '持股状态', field: 'gBz', visible: true, align: 'center', valign: 'middle'},
            {title: '变动比例', field: 'gBdbl', visible: true, align: 'center', valign: 'middle'},
            {title: '变动数量', field: 'gSharehdratio', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Gdtj.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Gdtj.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
Gdtj.openAddGdtj = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/gdtj/gdtj_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
Gdtj.openGdtjDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/gdtj/gdtj_update/' + Gdtj.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
Gdtj.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/gdtj/delete", function (data) {
            Feng.success("删除成功!");
            Gdtj.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("gdtjId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询列表
 */
Gdtj.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['dm'] = $("#dm").val();
    queryData['sharestype'] = $("#sharestype").val();
    Gdtj.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Gdtj.initColumn();
    var table = new BSTable(Gdtj.id, "/gdtj/list", defaultColunms);
    table.setPaginationType("server");
    Gdtj.table = table.init();
});
